package com.xindaoapp.happypet.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.xindao.photonics.fragments.manager.BaseFragment;
import com.xindaoapp.happypet.R;
import com.xindaoapp.happypet.api.ConstantsValue;
import com.xindaoapp.happypet.utils.Constants;
import com.xindaoapp.happypet.viewpager.SwitchTabViewPager;
import com.xindaoapp.happypet.viewpager.SwitchTabViewPager.TabSelector;
import com.xindaoapp.happypet.viewpager.ViewPagerAdapter;
import com.xindaoapp.happypet.viewpager.ViewPagerWindow;
import com.xindaoapp.happypet.viewpager.windows.ReplyWindow;
import com.xindaoapp.happypet.viewpager.windows.ReplyWindow.MessageTabType;

/**
 * 消息中心
 * 
 * @author chenghao
 */
@Deprecated
public class MessageCenterFragment extends BaseFragment {

    private SwitchTabViewPager pager;

    private ImageView message_push;
    private ImageView letter_push;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_message_center, container, false);
    }

    @Override
    protected void initViews(View view) {
        super.initViews(view);
        pager = (SwitchTabViewPager) view.findViewById(R.id.viewpager);
        message_push = (ImageView) view.findViewById(R.id.message_push);
        letter_push = (ImageView) view.findViewById(R.id.letter_push);
        pager.addTabs(
                new View[] {view.findViewById(R.id.tab_left_view),
                        view.findViewById(R.id.tab_center_view),
                        view.findViewById(R.id.tab_right_view)}, 0, true, false);
        ViewPagerWindow[] windows =
                new ViewPagerWindow[] {new ReplyWindow(getActivity(), MessageTabType.REPLY),
                        new ReplyWindow(getActivity(), MessageTabType.INFORM),
                        new ReplyWindow(getActivity(), MessageTabType.LETTER)};
        pager.addPagerWindows(windows);
        pager.setAdapter(new ViewPagerAdapter(windows));
        if (getArguments() != null) {
            pager.setCurrentItem(getArguments().getInt(Constants.KEY_SKIP_TAB_INDEX));
        }
        if (ConstantsValue.HAS_LETTER) {
            letter_push.setVisibility(View.VISIBLE);
        }
        if (ConstantsValue.HAS_MESSAGE) {
            // message_push.setVisibility(View.VISIBLE);
        }
        pager.setOnTabSelector(new TabSelector() {
            @Override
            public void onSelector0(int position) {
                pager.setTabSelector(position);
                if (position == 2) {
                    ConstantsValue.HAS_LETTER = false;
                    if (letter_push.getVisibility() == View.VISIBLE) {
                        letter_push.setVisibility(View.GONE);
                    }
                    sendClearReceiver();
                } else if (position == 0) {
                    ConstantsValue.HAS_MESSAGE = false;
                    if (message_push.getVisibility() == View.VISIBLE) {
                        message_push.setVisibility(View.GONE);
                    }
                    sendClearReceiver();
                }
            }
        });


    }

    @Override
    protected String getTitleName() {
        return "消息中心";
    }

    @Override
    protected boolean showRightView() {
        return false;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void sendClearReceiver() {
        if (message_push.getVisibility() == View.GONE && letter_push.getVisibility() == View.GONE) {
            // getActivity().sendBroadcast(new Intent(ConstantsValue.CLEAR_POINT));
        }
    }
}
